﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace STS.Pacjent
{
    public partial class dodajbadaniemoczu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            imie.Visible = false;
            nazwisko.Visible = false;
            Pesel.Visible = false;
            miasto.Visible = false;
            Master.FindControl("NavigationMenuR").Visible = false;
            Master.FindControl("NavigationMenu0").Visible = true;
            Master.FindControl("NavigationMenu").Visible = false;

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string strConnection = "Data Source=BZYLAK-DELL;Initial Catalog=MGR;Integrated Security=True";
            SqlConnection sqlConnection = new SqlConnection(strConnection);
            String SQLQuery = "SELECT id_pacjenta, imie, nazwisko, pesel, miejscowosc FROM dane_pacjentow where id_osrodka=" + Main.idosrodka.ToString() + " and pesel=" + TextBox1.Text;
            SqlCommand command = new SqlCommand(SQLQuery, sqlConnection);
            SqlDataReader Dr;
            sqlConnection.Open();
            Dr = command.ExecuteReader();

            if (Dr.HasRows)
            {
                Dr.Read();
                imie.Visible = true;
                nazwisko.Visible = true;
                Pesel.Visible = true;
                miasto.Visible = true;

                id_pacjenta.Text = Dr["id_pacjenta"].ToString();
                imie.Text = Dr["imie"].ToString();
                nazwisko.Text = Dr["nazwisko"].ToString();
                Pesel.Text = Dr["pesel"].ToString();
                miasto.Text = Dr["miejscowosc"].ToString();

            }
            else
            {
                imie.Visible = true;
                imie.Text = "Brak Pacjenta, spróbuj wpisać PESEL ponownie";
            }
            Dr.Close();

            data.Text = DateTime.Now.ToString();
        }
    }
}